package elmar.swt;

public class BinTreeCoordinateHelper {

	public static int getPosX(int idx) {
		if (idx == 0)
			return 0;
		int nBefore = (1 << getPosY(idx)) - 1;
		return idx - nBefore;
	}

	public static int getPosY(int _idx) {
		return Util.log2(_idx + 1);
	}

	public static int getNHalfUnitX(int _nNode) {
		if (_nNode < 2)
			return 0;
		int nDepth = getPosY(_nNode-1);
		return ((1<<(nDepth - 1))-1)*2;
	}

}
